from dataclasses import dataclass, asdict
from typing import List, Optional

# 初筛通过
@dataclass
class CandidateSummary:
    candidate_name: str
    match_score: float
    core_skills_matched: List[str]
    soft_skills_detected: List[str]
    education_summary: str
    experience_summary: str
    resume_file_url: str
    interview_recommendation: str
    highlights: Optional[List[str]] = None

    def to_dict(self):
        return {
            "candidate_name": self.candidate_name,
            "match_score": self.match_score,
            "core_skills_matched": self.core_skills_matched,
            "soft_skills_detected": self.soft_skills_detected,
            "education_summary": self.education_summary,
            "experience_summary": self.experience_summary,
            "resume_file_url": self.resume_file_url,
            "interview_recommendation": self.interview_recommendation,
            "highlights": self.highlights or []
        }

# 初筛不通过



@dataclass
class FeedbackItem:
    dimension: str
    score: float
    max_score: float
    comments: str

    def to_dict(self):
        return asdict(self)


@dataclass
class ScreeningResult:
    passed: bool
    final_score: float
    threshold_score: float
    feedback: List[FeedbackItem]
    suggestions: List[str]

    def to_dict(self):
        return {
            "pass": self.passed,
            "final_score": self.final_score,
            "threshold_score": self.threshold_score,
            "feedback": [item.to_dict() for item in self.feedback],
            "suggestions": self.suggestions
        }


# 示例数据填充
if __name__ == "__main__":
    feedback_items = [
        FeedbackItem("硬技能匹配度", 30.0, 40.0, "缺少 Python 和 Django 的实际经验"),
        FeedbackItem("软技能与职业素养", 10.0, 20.0, "沟通能力体现不清晰"),
        FeedbackItem("教育背景与经验", 15.0, 20.0, "经验年限略低于岗位要求"),
        FeedbackItem("简历完整性与表达", 7.5, 20.0, "项目描述不清晰，未量化成果"),
    ]

    result = ScreeningResult(
        passed=False,
        final_score=62.5,
        threshold_score=70.0,
        feedback=feedback_items,
        suggestions=[
            "补充相关项目中使用 Python/Django 的经历",
            "在简历中明确体现沟通能力或团队合作案例",
            "标注项目中个人贡献与结果，使用量化指标",
            "建议在 Github 添加更多公开项目链接"
        ]
    )

    print(result.to_dict())  # 可以用于 JSON 接口返回